{{define "premium_user_setup"}}
{{template "cp_head" .}}

<div class="page-header">
    <h2>Manage Premium</h2>
</div>

{{template "cp_alerts" .}}


<div class="row">
    <div class="col-lg-12">
        <section class="card">
            <header class="card-header">
                <h1 class="card-title">Redeem code</h1>
            </header>
            <div class="card-body">
                <form method="post" data-async-form>
                    <input type="text" class="form-control mb-2" name="code">
                    <button type="submit" value="Redeem code" class="btn btn-success"
                        formaction="/premium/redeemcode">Redeem code</button>
                    <button type="submit" value="Check code" class="btn btn-primary"
                        formaction="/premium/lookupcode">Check code</button>
                </form>
                <div class="mt-5">
                <p>If you're coming here after making a payment on patreon, <a href="https://support.patreon.com/hc/en-us/articles/212052266-Getting-Discord-access" target="_blank">you need to connect your discord to patreon</a>
                Once that is done, your slots will appear below automatically with-in 10 minutes.
                Premium slots are assigned to servers, you can assign them to any server you have manage server permissions on.
                If you don't see your slots after 10 minutes, please contact us on the <a href="https://discord.gg/4udtcA5" target="_blank">support server.</a></p>
                <p>To learn more about what premium features and how to get premium, check the <a href="/premium-perks" target="_blank">premium perks</a> list.</p>
                </div>

                {{if .QueriedCode}}
                <ul>
                    <li>Code: <code>{{.QueriedCode.Code}}</code></li>
                    <li>Permanent: <code>{{.QueriedCode.Permanent}}</code></li>
                    <li>Duration: <code>{{.QueriedCode.Duration}}</code></li>
                </ul>
                {{end}}
            </div>
        </section>
        <!-- /.panel -->
    </div>
    <!-- /.col-lg-12 -->
</div>
<div class="row">
    {{$dot := .}}
    {{range .PremiumSlots}}
    <div class="col-md-6 mb-2">
        <section class="card {{if .GuildID.Valid}}card-featured card-featured-success{{end}}">
            <header class="card-header">
                <h2 class="card-title">Slot: {{.Title}}</h2>
            </header>

            <div class="card-body">
                <ul>
                    <li>{{if not .Permanent}}Expires in:
                        <code>{{humanizeDurationHours (call $dot.PremiumSlotDurationRemaining .)}}</code>{{else}}Expires
                        never{{end}}.
                    </li>
                    {{if .Message}}<li>{{.Message}}</li>{{end}}
                </ul>

                <form action="/premium/updateslot/{{.ID}}" method="post" data-async-form>
                    <div class="form-group">
                        <label for="slot-{{.ID}}">Assign this premium slot to a server</label>
                        <select name="GuildID" class="form-control" id="slot-{{.ID}}">
                            {{$found := false}}
                            <option value="0" {{if not .GuildID.Valid}}{{$found = true}} selected{{end}}>None</option>


                            {{$selected := .GuildID.Int64}}
                            {{range $dot.UserGuilds}}{{if .Connected}}
                            <option value="{{.ID}}" {{if eq .ID $selected}}{{$found = true}} selected {{end}}>{{.Name}}
                            </option>
                            {{end}}{{end}}

                            {{if not $found}}
                            <option value="{{.GuildID.Int64}}" selected>Unknown server ({{.GuildID.Int64}})</option>
                            {{end}}
                        </select>
                    </div>

                    <button type="submit" class="btn btn-success mt-2">Update premium slot</button>
                </form>
            </div>
        </section>
        <!-- /.panel -->
    </div>
    {{end}}
    <!-- /.col-lg-12 -->
</div>
{{template "cp_footer" .}}

{{end}}


{{define "cp_premium_detach"}}
{{template "cp_head" .}}

<div class="page-header">
    <h2>Detach premium slot</h2>
</div>

{{template "cp_alerts" .}}

<div class="row">
    <div class="col-lg-12">
        <section class="card card-featured card-featured-success">
            <div class="card-body">
                <div class="row">
                    <h2><a href="/manage/{{.ActiveGuild.ID}}/home">Back to home</a></h2>
                </div>
            </div>
        </section>
        <!-- /.panel -->
    </div>
    <!-- /.col-lg-12 -->
</div>
<!-- /.row -->

{{template "cp_footer" .}}

{{end}}
